package com.xiaochong.tir.api.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.api.component.HbaseBaseQueryComponent;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.common.data.hbasepo.BroaderIndex;
import com.xiaochong.tir.common.data.hbasepo.CurrentcyHighOrLow;
import com.xiaochong.tir.common.data.hbasepo.IndustryIndex;
import com.xiaochong.tir.common.data.hbasepo.MoneyEffect;
import com.xiaochong.tir.common.data.hbasepo.QuantumEnergy;
import com.xiaochong.tir.common.data.hbasepo.WeightIndex;
import com.xiaochong.tir.common.data.hbasepo.WeightsPerformance;
import com.xiaochong.tir.common.data.mapper.CurrencyIndustryCategoryMapper;
import com.xiaochong.tir.common.data.mapper.KLineBroaderIndexMapper;
import com.xiaochong.tir.common.data.po.KLineBroaderIndex;
import com.xiaochong.tir.common.data.vo.*;
import com.xiaochong.tir.common.data.mapper.KLineMapper;
import com.xiaochong.tir.common.data.po.KLine;
import com.xiaochong.tir.common.data.vo.ApiChartYObject;
import com.xiaochong.tir.common.data.vo.ApiChartYValue;
import com.xiaochong.tir.common.data.vo.ApiIndustryIndexVo;
import com.xiaochong.tir.common.data.vo.ApiIndustryTabInfoVo;
import com.xiaochong.tir.common.data.vo.ApiMarketAnalysisTotalResult;
import com.xiaochong.tir.common.data.vo.ApiMarketIndexVo;
import com.xiaochong.tir.common.data.vo.ApiMarketInterpretationChange;
import com.xiaochong.tir.common.data.vo.ApiMarketWeightsPerformance;
import com.xiaochong.tir.common.data.vo.ApiResultVo;
import com.xiaochong.tir.common.data.vo.ApiWeightIndexKlineVo;
import com.xiaochong.tir.common.data.vo.ApiWeightIndexVo;
import com.xiaochong.tir.common.data.vo.ChartVo;
import com.xiaochong.tir.common.data.vo.GraliIntensity;
import com.xiaochong.tir.common.data.vo.KlineWeightIndex;
import com.xiaochong.tir.common.data.vo.MoreChartVo;
import com.xiaochong.tir.common.data.vo.WeightIndexLastInfo;
import com.xiaochong.tir.common.exception.hbase.HbaseCloseExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseConnectionExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseGetTableExcetion;
import com.xiaochong.tir.common.util.*;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by org on 2018/4/27.
 */
@Service
public class TokenIndexRankService {
    @Autowired
    private RedisServer rediscConfig ;
    @Autowired
    private HbaseBaseQueryComponent hbaseBaseQueryComponent;
    @Autowired
    private CurrencyIndustryCategoryMapper currencyIndustryCategoryMapper;

    @Autowired
    private KLineMapper kLineMapper;

    @Autowired
    private KLineBroaderIndexMapper kLineBroaderIndexMapper;

    /**
     * 大盘指数
     * @param type
     * @return
     */
    public ApiResultVo getGrailIndex(int type){
        LogTrace.info("大盘指数","type",String.valueOf(type));
        Long start = System.currentTimeMillis();
        ApiResultVo<ApiMarketIndexVo> resultVo = new ApiResultVo<>();
        ApiMarketIndexVo voList = new ApiMarketIndexVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();
        voList.setChart(chartVo);
        try {
            if (type == 1){//查询所有数据
                //从redis获取数据，如果存在直接返回前端，否则去hbase获取，redis失效时间5分钟
                if(rediscConfig.getExpire(RedisKeysUtils.TIR_BROADER_INDEX_ALL_DATA) > 0){
                    Long redisStart = System.currentTimeMillis();
                    String redisDate = rediscConfig.get(RedisKeysUtils.TIR_BROADER_INDEX_ALL_DATA);
                    if(StringUtils.isBlank(redisDate)){//如果数据没有，再去组装
                         this.MakeGrailIndexToCacheOfCalculation(voList);
                    }
                    voList = JSON.parseObject(redisDate,ApiMarketIndexVo.class);
                    LogTrace.info("大盘指数reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-redisStart));
                }else{//去hbase获取并且保存到redis中
                    voList = this.MakeGrailIndexToCacheOfCalculation(voList);
                }
            }else {//查询当前最新数据
                String grailIndex = rediscConfig.get(RedisKeysUtils.TIR_BROADER_INDEX);
                LogTrace.info("大盘指数-从reids获取的数据","返回数据",grailIndex);
                if(StringUtils.isNotBlank(grailIndex)){
                    BroaderIndex bi = JSON.parseObject(grailIndex,BroaderIndex.class);
                    x.add(String.valueOf(bi.getCreateTime().getTime()));
                    y.add(bi.getBroaderIndex().toString());
                    voList.setChange(bi.getBroaderRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    voList.setIndex(bi.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
                    chartVo.setX(x);
                    chartVo.setY(y);
                }
            }
            if(voList != null){
                x = voList.getChart().getX();
                y = (List<String>) voList.getChart().getY();
            }
            if(x == null || x.size() == 0 || y == null || y.size() == 0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else {
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
            voList.setTir("大盘指数");
            resultVo.setData(voList);
            Long end = System.currentTimeMillis();
            LogTrace.info("大盘指数","耗时",String.valueOf(end-start));
            return resultVo;
        }catch (Exception e){
            Long end = System.currentTimeMillis();
            LogTrace.info("大盘指数","耗时",String.valueOf(end-start));
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            e.printStackTrace();
            LogTrace.error("大盘指数"+type,e);
            return resultVo;
        }

    }

    /**
     * 大盘指数数据获取
     * @param rowKey
     * @param vo
     * @param isToday
     * @param voList
     * @param x
     * @param y
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public void getGrailIndexOfHours(String rowKey,ChartVo vo,boolean isToday,ApiMarketIndexVo voList,
                                     List<String> x,List<String> y) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        Long hstart = System.currentTimeMillis();
        String grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_NAME
                , HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_FAMILY
                , HbaseTableUtils.EVERY_DAY_BROADER_INDEX_QUALIFIER
                , rowKey );
        LogTrace.info("hbase数据查询","是否存在数据"+rowKey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
        LogTrace.info("大盘指数hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        if (StringUtils.isBlank(grailStr)) return;
        List<BroaderIndex> hlist = JSONObject.parseArray(grailStr, BroaderIndex.class);
        if (hlist != null && hlist.size() > 0) {
            for (int i = 0; i < hlist.size(); i++) {
                BroaderIndex hbi = hlist.get(i);
                if (hbi == null || hbi.getCreateTime() == null || hbi.getBroaderIndex() == null) continue;
                //存入十二个小时以内数据
                if (DateUtils.getDaysBetweenTwoHours(new Date(), hbi.getCreateTime()) <= 12) {
                    x.add(String.valueOf(hbi.getCreateTime().getTime()));
                   // x.add(hbi.getCreateTime() != null ? DateUtils.dateFormatString(hbi.getCreateTime(), DateUtils.format_ymdhm_x) : "");
                    y.add(hbi.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
                }
            }

            if(isToday){//取最后一条数据
                voList.setChange(hlist.get(hlist.size() - 1).getBroaderRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                voList.setIndex(hlist.get(hlist.size() - 1).getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
            }
        }
    }

    /**
     * 权重指数
     * @param type
     * @return
     */
    public ApiResultVo<ApiWeightIndexVo> getWeightIndex(int type) {
        LogTrace.info("权重指数","type",String.valueOf(type));
        Long start = System.currentTimeMillis();
        ApiResultVo<ApiWeightIndexVo> resultVo = new ApiResultVo<>();
        ApiWeightIndexVo voList = new ApiWeightIndexVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        LogTrace.info("权重指数","参数type",String.valueOf(type));
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();
        try {
            if (type == 1){//查询所有数据 ,否则查询最新的一次
                //从redis获取数据，如果存在直接返回前端，否则去hbase获取，redis失效时间5分钟
                Long redisStart = System.currentTimeMillis();
                String redisDate = rediscConfig.get(RedisKeysUtils.TIR_WEIGHT_INDEX_ALL_DATA);
                LogTrace.info("权重指数reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-start));
                if(StringUtils.isNotBlank(redisDate)){
                    voList = JSON.parseObject(redisDate,ApiWeightIndexVo.class);
                }else{
                    this.MakeWeightIndexToCacheOfCalculation(voList);
                }
                if(voList != null){
                    x = voList.getChart().getX();
                    y = (List<String>) voList.getChart().getY();
                }
            }else {//查询当前最新数据
                String grailIndex = rediscConfig.get(RedisKeysUtils.TIR_WEIGHT_INDEX);
                if(StringUtils.isNotBlank(grailIndex)){
                    WeightIndex bi = JSON.parseObject(grailIndex,WeightIndex.class);
                    x.add(String.valueOf(bi.getCreateTime().getTime()));
                    y.add(bi.getWeightIndex()!=null?bi.getWeightIndex().toString():"");
                    String changWeight =  bi.getWeightRiseFall()!=null?bi.getWeightRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString():"";
                    //去第一条数据
                    voList.setChange(changWeight.toString());
                    voList.setIndex(bi.getWeightIndex()!=null?bi.getWeightIndex().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    chartVo.setX(x);
                    chartVo.setY(y);
                    voList.setChart(chartVo);
                }
            }
            if(x == null || x.size() == 0 || y.size() == 0 || y == null){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else {
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
        }catch (Exception e){
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            LogTrace.error("权重指数",e);
            e.printStackTrace();
        }
        resultVo.setData(voList);
        voList.setTir("权重指数");
        Long end = System.currentTimeMillis();
        LogTrace.info("权重指数","耗时",String.valueOf(end-start));
        return resultVo;
    }
    public void getWeightIndexOfData(String rowKey,ChartVo vo,boolean isToday,ApiWeightIndexVo voList,
                                     List<String> x,List<String> y) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        Long hstart = System.currentTimeMillis();
        String grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_NAME
                , HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_FAMILY
                , HbaseTableUtils.CALCULATE_TICKER_QUALIFIER
                , HbaseTableUtils.HOME_INDEX_EVERY_DAY_WEIGHTINDEX_ROWKEY+rowKey);
        LogTrace.info("hbase数据查询","是否存在数据"+rowKey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
        LogTrace.info("权重指数","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        if(StringUtils.isBlank(grailStr)) return;
        /*Map<String,Object> hmap = (Map<String, Object>) JSONObject.parse(grailStr);
        for (Map.Entry xm :hmap.entrySet()){
            if("weightIndices".equals(xm.getKey())){
                grailStr =  JSON.toJSONString(xm.getValue());
            }
        }*/
       // System.out.println(grailStr);
        List<WeightIndex>  hlist = JSON.parseArray(grailStr,WeightIndex.class);
        if(hlist != null && hlist.size() > 0){
            for (int i=0;i<hlist.size();i++){
                WeightIndex hbi =  (WeightIndex)hlist.get(i);
                if(hbi == null || hbi.getCreateTime() == null || hbi.getWeightIndex()== null){
                    continue;  //内容不完整直接过滤
                }
                //存入十二个小时以内数据
                if(DateUtils.getDaysBetweenTwoHours(new Date(),hbi.getCreateTime())<=12) {
                    //x.add(DateUtils.dateFormatString(hbi.getCreateTime(), DateUtils.format_ymdhm_x));
                    x.add(hbi.getCreateTime()!=null?String.valueOf(hbi.getCreateTime().getTime()):"");
                    y.add(hbi.getWeightIndex()!=null?hbi.getWeightIndex().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                }
            }
            if(isToday){ //取最后一条数据
                voList.setChange(hlist.get(hlist.size()-1).getWeightRiseFall()!=null?hlist.get(hlist.size()-1).getWeightRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                voList.setIndex(hlist.get(hlist.size()-1).getWeightIndex()!=null?hlist.get(hlist.size()-1).getWeightIndex().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
            }
        }
    }
    public ApiResultVo<List<ApiIndustryTabInfoVo>> getIndustryTabInfo() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
        resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            List<ApiIndustryTabInfoVo> listvo = currencyIndustryCategoryMapper.selectIndustryTabInfo();
            LogTrace.info("获取行业分类","数据",JSON.toJSONString(listvo));
            resultVo.setData(listvo);
        }catch (Exception e){
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            e.printStackTrace();
            LogTrace.error("获取行业分类",e);
        }
        return resultVo;
    }

    /**
     * 根据id获取行业的指数数据，
     * @param type 等于1代表第一次获取所有数据，否则获取最新数据
     * @param industryId  行业id
     * @return
     */
    public ApiResultVo getAllIndustryIndex(Integer type, Integer industryId,String industry) {
        Long start = System.currentTimeMillis();
        ApiResultVo<ApiIndustryIndexVo> resultVo = new ApiResultVo<>();
        ApiIndustryIndexVo voList = new ApiIndustryIndexVo();
        LogTrace.info("行业指数-传参","type-industryId-industry",type+"-"+industryId+"-"+industry);
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        if(industryId == null){
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            return resultVo;
        }
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYValue> y = new LinkedList<>();
        try {
            //获取数据库中的名称
            if (type == 1){//查询所有数据
                //从redis获取数据，如果存在直接返回前端，否则去hbase获取，redis失效时间5分钟
                String redisDate = rediscConfig.get(RedisKeysUtils.TIR_INDUSTRY_INDEX_ALL_DATA+industryId);
                LogTrace.info("行业指数reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-start));
                if(StringUtils.isNotBlank(redisDate)){
                    voList = JSON.parseObject(redisDate,ApiIndustryIndexVo.class);
                }else{//去hbase获取并且保存到redis中
                    this.MakeIndustryToCacheOfCalculation(voList,industryId);
                }
                if(voList != null){
                    x = voList.getChart().getX();
                    y = (List<ApiChartYValue>) voList.getChart().getY();
                }
                
            }else {//查询当前最新数据
                String grailIndex = rediscConfig.get(RedisKeysUtils.TIR_INDUSTRY_INDEX+industryId);
                if(StringUtils.isNotBlank(grailIndex)){
                    IndustryIndex bi = JSON.parseObject(grailIndex,IndustryIndex.class);
                    x.add(String.valueOf(bi.getCreateTime().getTime()));
                    ApiChartYValue yValue = new ApiChartYValue();
                    yValue.setValue(bi.getIndustryIndex()!=null?bi.getIndustryIndex().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    yValue.setContent2(bi.getIndustryRiseFall()!=null?bi.getIndustryRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    y.add(yValue);
                    voList.setChange(bi.getIndustryRiseFall().toString());
                    voList.setIndex(bi.getIndustryIndex().doubleValue());
                    chartVo.setX(x);
                    chartVo.setY(y);
                    voList.setChart(chartVo);
                }
            }
            resultVo.setData(voList);
            voList.setTir("行业指数");
            voList.setIndustry(industry);
            voList.setIndustryId(industryId);
            if(x.size() == 0  || x == null || y == null || y.size() == 0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else{
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
            Long end = System.currentTimeMillis();
            LogTrace.info("行业指数","耗时",String.valueOf(end-start));
            return resultVo;
        }catch (Exception e){
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            e.printStackTrace();
            LogTrace.error("行业指数",e);
            Long end = System.currentTimeMillis();
            LogTrace.info("行业指数","耗时",String.valueOf(end-start));
            return resultVo;
        }
    }

    /**
     * 遍历数据找出近12小时行业指数数据
     * @param rowKey hbase列
     * @param vo  图标
     * @param isToday  是否今天
     * @param voList  数据
     * @param industryId id
     * @param x 图标x轴
     * @param y 图标y轴
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public void getIndustryChartData(String rowKey,ChartVo vo,boolean isToday,ApiIndustryIndexVo voList,int industryId,
                                     List<String> x,List<ApiChartYValue> y) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        String grailStr = null;
        Long hstart = System.currentTimeMillis();
        grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_NAME
                , HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_FAMILY
                , HbaseTableUtils.CALCULATE_TICKER_QUALIFIER
                , industryId+"@"+rowKey
                );
        LogTrace.info("hbase数据查询","是否存在数据"+rowKey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
        LogTrace.info("行业指数hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        if(StringUtils.isBlank(grailStr)) return ; //vo
        /*Map<String,Object> hmap = (Map<String, Object>) JSONObject.parse(grailStr);
        for (Map.Entry xm :hmap.entrySet()){
            if("industryIndices".equals(xm.getKey())){
                grailStr =  JSON.toJSONString(xm.getValue());
            }
        }
        Map<String,Object> hbaseIndustryMap = JSON.parseObject(grailStr);
        List<IndustryIndex> bil = JSON.parseArray(JSON.toJSONString(hbaseIndustryMap.get(industryId)),IndustryIndex.class);*/
        //循环获取每个行业
        List<IndustryIndex> bil = JSON.parseArray(grailStr,IndustryIndex.class);
        if(bil == null || bil.size() ==0) return;
        ApiChartYValue yValue = null;
        for(int k=0;k<bil.size();k++){
            IndustryIndex bi = bil.get(k);
            if(bi == null || bi.getCreateTime() == null || bi.getIndustryIndex()== null || bi.getIndustryRiseFall()== null){
                continue;  //内容不完整直接过滤
            }
            //存入十二个小时以内数据
            if(DateUtils.getDaysBetweenTwoHours(new Date(),bi.getCreateTime())<=12) {
               // x.add(DateUtils.dateFormatString(bi.getCreateTime(), DateUtils.format_ymdhm_x));
                x.add(String.valueOf(bi.getCreateTime().getTime()));
                yValue = new ApiChartYValue();
                yValue.setValue(bi.getIndustryIndex()!=null?bi.getIndustryIndex().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                yValue.setContent2(bi.getIndustryRiseFall()!=null?bi.getIndustryRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                y.add(yValue);
            }
        }
        //取最后一条数据
        if(isToday){
            voList.setChange(bil.get(bil.size()-1).getIndustryRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
            voList.setIndex(bil.get(bil.size()-1).getIndustryIndex().setScale(2,BigDecimal.ROUND_DOWN).doubleValue());
        }
    }
    /**
     * 赚钱效应图标
     * @return
     */
    public ApiResultVo getMarkMoneyEffect() {
        Long start = System.currentTimeMillis();
        ApiResultVo<GraliIntensity> resultVo = new ApiResultVo<>();
        GraliIntensity vo = new GraliIntensity();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            String redisDate = rediscConfig.get(RedisKeysUtils.MARK_MONEY_EFFECT_FIVE_DATA);
            LogTrace.info("赚钱效应reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-start));
            if(StringUtils.isNotBlank(redisDate)){
                vo = JSON.parseObject(redisDate,GraliIntensity.class);
            }else{//去hbase获取并且保存到redis中
                this.MarkMoneyEffectToCacheCalculation(vo);
            }
            if(vo == null || vo.getChart() == null || vo.getChart().getX() == null || vo.getChart().getX().size() == 0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else{
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
            resultVo.setData(vo);
            Long end = System.currentTimeMillis();
            LogTrace.info("赚钱效应","耗时",String.valueOf(end-start));
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            LogTrace.error("赚钱效应",e);
            Long end = System.currentTimeMillis();
            LogTrace.info("赚钱效应","耗时",String.valueOf(end-start));
            return resultVo;
        }
    }

    /**
     * 权重表现
     * @return
     */
    public ApiResultVo<ApiMarketWeightsPerformance> getMarketWeightsPerformance() {
        Long start = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo();
        ApiMarketWeightsPerformance vo = new ApiMarketWeightsPerformance();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            String redisDate = rediscConfig.get(RedisKeysUtils.MARKET_WEIGHTS_PERFORMANCE);
            LogTrace.info("权重表现reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-start));
            if(StringUtils.isNotBlank(redisDate)){
                vo = JSON.parseObject(redisDate,ApiMarketWeightsPerformance.class);
            }else{//去hbase获取并且保存到redis中
                this.MarketWeightsPerformanceToCacheCalculation(vo);
            }
            if(vo == null || vo.getChart() == null || vo.getChart().getX() == null || vo.getChart().getX().size() == 0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else{
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
            resultVo.setData(vo);
            Long end = System.currentTimeMillis();
            LogTrace.info("权重表现","耗时",String.valueOf(end-start));
            return resultVo;
        } catch (Exception e) {
            Long end = System.currentTimeMillis();
            LogTrace.info("权重表现","耗时",String.valueOf(end-start));
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            LogTrace.error("权重表现",e);
            return resultVo;
        }

    }
    /**
     * 量能变化
     * @return
     */
    public ApiResultVo getMarketInterpretationChange() {
        Long start = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        ApiMarketInterpretationChange vo = new ApiMarketInterpretationChange();
        try {
            String redisDate = rediscConfig.get(RedisKeysUtils.MARKET_INTERPRETATION_CHANGE);
            LogTrace.info("量能变化reis查询数据","耗时",String.valueOf(System.currentTimeMillis()-start));
            if(StringUtils.isNotBlank(redisDate)){
                vo = JSON.parseObject(redisDate,ApiMarketInterpretationChange.class);
            }else{//去hbase获取并且保存到redis中
                this.MarketInterpretationChangeToCacheCalculation(vo);
            }
            if(vo == null || vo.getChart() == null || vo.getChart().getX() == null || vo.getChart().getX().size() == 0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }else{
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }
            resultVo.setData(vo);
            Long end = System.currentTimeMillis();
            LogTrace.info("量能变化","耗时",String.valueOf(end-start));
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            LogTrace.error("量能变化",e);
            Long end = System.currentTimeMillis();
            LogTrace.info("量能变化","耗时",String.valueOf(end-start));
            return resultVo;
        }
    }


    /**
     * 大盘分析
     * @return
     */
    public ApiResultVo<ApiMarketAnalysisTotalResult> getMarketAnalysisTotalResult() {
        Long start = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo();
        ApiMarketAnalysisTotalResult vo = new ApiMarketAnalysisTotalResult();
        resultVo.setData(vo);
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            //去redis中取量能变化、赚钱效应、权重表现  WeightsPerformance
            String grailIndex = rediscConfig.get(RedisKeysUtils.INDEX_EVERY_DAY_RECORDING);
            LogTrace.info("大盘分析-量能变化、赚钱效应、权重表现redis数据","数据",grailIndex);
            //去redis涨跌统计
            String highOrLow = rediscConfig.get(RedisKeysUtils.TIR_CHANGE_STATISTICS);
            LogTrace.info("大盘分析-涨跌统计redis数据","数据",highOrLow);
            if(StringUtils.isBlank(grailIndex) && StringUtils.isBlank(highOrLow)){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                return resultVo;
            }
            Map<String,Object> marketMap = JSON.parseObject(grailIndex);
            BigDecimal scoreMoneyEffect;
            BigDecimal scoreWeightsPerformance;
            BigDecimal scoreStatistics ;
            BigDecimal scoreQuantumEnergy ;
            BigDecimal total = new BigDecimal(0);
            if(marketMap != null){
                for (Map.Entry m :marketMap.entrySet()){
                    if("moneyEffect".equals(m.getKey())){ //MoneyEffect
                        MoneyEffect bi = JSON.parseObject(JSON.toJSONString(m.getValue()),MoneyEffect.class);
                        if(bi != null && bi.getScore() != null){
                            LogTrace.info("大盘强度分析","赚钱效应分数",String.valueOf(bi.getScore()));
                            scoreMoneyEffect = new BigDecimal(bi.getScore()).multiply(BigDecimal.valueOf(0.15));
                            total = total.add(scoreMoneyEffect);
                            vo.setMakeMoneyEffect(bi.getComment()!=null?bi.getComment():"");
                        }
                    }else if("weightsPerformance".equals(m.getKey())){
                        WeightsPerformance bi = JSON.parseObject(JSON.toJSONString(m.getValue()),WeightsPerformance.class);
                        if(bi != null && bi.getScore() != null){
                            scoreWeightsPerformance = new BigDecimal(bi.getScore()).multiply(BigDecimal.valueOf(0.3));
                            total = total.add(scoreWeightsPerformance);
                            LogTrace.info("大盘强度分析","权重表现分数",String.valueOf(bi.getScore()));
                            vo.setWeightPerformance(bi.getComment()!=null?bi.getComment():"");
                        }
                    }else if("quantumEnergy".equals(m.getKey())){
                        QuantumEnergy bi = JSON.parseObject(JSON.toJSONString(m.getValue()),QuantumEnergy.class);
                        if(bi != null && bi.getScore() != null){
                            scoreQuantumEnergy = new BigDecimal(bi.getScore()).multiply(BigDecimal.valueOf(0.25));
                            total = total.add(scoreQuantumEnergy);
                            LogTrace.info("大盘强度分析","量能变化分数",String.valueOf(bi.getScore()));
                            vo.setEnergyChange(bi.getComment()!=null?bi.getComment():"");
                        }
                    }
                }
            }
            if (StringUtils.isNotBlank(highOrLow)){
                CurrentcyHighOrLow hl = JSON.parseObject(highOrLow,CurrentcyHighOrLow.class);
                scoreStatistics = new BigDecimal(Double.valueOf(hl.getScore())).multiply(BigDecimal.valueOf(0.3));
                total = total.add(scoreStatistics);
                LogTrace.info("大盘强度分析","涨跌统计分数分数",String.valueOf(hl.getScore()));
                vo.setStatistics(hl.getEvaluate());
            }
            //计算4个比例分数，以及给出评语
            LogTrace.info("大盘强度","total分数",total.toString());
            vo.setMarketScore(String.valueOf(total.setScale(1,BigDecimal.ROUND_DOWN)));
            double num = Double.valueOf(String.valueOf(total));
            if(num < 4){
                vo.setResult("大盘处于走弱态势");
            }else if(num >= 4 && num < 6){
                vo.setResult("大盘处于盘整态势");
            }else{
                vo.setResult("大盘处于走强态势");
            }
            //获取近7日趋势
            vo.setLast7status(rediscConfig.get(RedisKeysUtils.BROADER_DATA_7_STATUS));
            //获取近30日趋势
            vo.setLast30status(rediscConfig.get(RedisKeysUtils.BROADER_DATA_30_STATUS));

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            Long end = System.currentTimeMillis();
            LogTrace.info("获取行业分类","耗时",String.valueOf(end-start));
            return resultVo;
        }catch (Exception e){
            LogTrace.error("获取行业分类",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            return resultVo;
        }

    }

    /**
     * 5分钟组装大盘指数放入redis中，缓存5分钟，触发
     * @return
     */
    public ApiResultVo MakeGrailIndexToCache(){
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ApiMarketIndexVo listVo = new ApiMarketIndexVo();
            this.MakeGrailIndexToCacheOfCalculation(listVo);//去组装
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装大盘指数放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }

    /**
     * 5分钟组装大盘指数放入redis中，缓存5分钟
     * @return
     * @throws Exception
     */
    public ApiMarketIndexVo MakeGrailIndexToCacheOfCalculation(ApiMarketIndexVo voList) throws Exception{
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();
        String keyRow = "";//判断今天的小时，判断是否需要昨天的，如果需要计算昨日的日期，
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        if(hourStrInt < 12){
            keyRow = DateUtils.getNextDayDateYMD(-1);
        }
        if(StringUtils.isNotBlank(keyRow)){//如果需要获取昨日
            this.getGrailIndexOfHours(keyRow,chartVo,false,voList,x,y);
        }
        //获取今日数据
        this.getGrailIndexOfHours(DateUtils.getCurrentDateString(),chartVo,true,voList,x,y);
        chartVo.setX(x);
        chartVo.setY(y);
        voList.setChart(chartVo);
        if(x.size() > 0 && y.size() > 0){
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.TIR_BROADER_INDEX_ALL_DATA,JSON.toJSONString(voList),300L);
        }
        return voList;
    }

    /**
     * 5分钟组装权重指数放入redis中，缓存5分钟，触发
     * @return
     */
    public ApiResultVo MakeWeightIndexToCache() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ApiWeightIndexVo listVo = new ApiWeightIndexVo();
            this.MakeWeightIndexToCacheOfCalculation(listVo);//去组装
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装权重指数放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }

    /**
     * 5分钟组装权重指数放入redis中，缓存5分钟，组装
     * @param voList
     * @throws Exception
     */
    public void MakeWeightIndexToCacheOfCalculation( ApiWeightIndexVo voList) throws  Exception{
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();
        //判断今天的小时，判断是否需要昨天的，如果需要计算昨日的日期，
        String keyRow = "";
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        if(hourStrInt < 12){
            keyRow = DateUtils.getNextDayDateYMD(-1);
        }
        if(StringUtils.isNotBlank(keyRow)){//如果需要获取昨日
            this.getWeightIndexOfData(keyRow,chartVo,false,voList,x,y);
        }
        //获取今日数据
        this.getWeightIndexOfData(DateUtils.getCurrentDateString(),chartVo,true,voList,x,y);
        chartVo.setX(x);
        chartVo.setY(y);
        voList.setChart(chartVo);
        if(x.size() > 0 && y.size() > 0){
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.TIR_WEIGHT_INDEX_ALL_DATA,JSON.toJSONString(voList),300L);
        }
    }
    /**
     * 5分钟组装行业指数放入redis中，缓存5分钟，触发
     * @return
     */
    public ApiResultVo MakeIndustryToCacheOf() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ApiIndustryIndexVo listVo = new ApiIndustryIndexVo();
            //获取所有行业,组装每个行业数据放到redis中
            List<ApiIndustryTabInfoVo> listvo = currencyIndustryCategoryMapper.selectIndustryTabInfo();
            if(listvo != null && listvo.size() > 0){
                for(ApiIndustryTabInfoVo entity : listvo){
                    this.MakeIndustryToCacheOfCalculation(listVo,entity.getIndustryId());//去组装
                }
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装行业指数放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }
    /**
     * 5分钟组装行业指数放入redis中，缓存5分钟，组装
     * @param voList
     * @throws Exception
     */
    private void MakeIndustryToCacheOfCalculation(ApiIndustryIndexVo voList,int industryId) throws Exception{
        ChartVo chartVo = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYValue> y = new LinkedList<>();
        //判断今天的小时，判断是否需要昨天的，如果需要计算昨日的日期，
        String keyRow = "";
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        if(hourStrInt < 12){
            keyRow = DateUtils.getNextDayDateYMD(-1);
        }
        if(StringUtils.isNotBlank(keyRow)){//如果需要获取昨日
            this.getIndustryChartData(keyRow,chartVo,false,voList,industryId,x,y);
        }
        //获取今日数据
        this.getIndustryChartData(DateUtils.getCurrentDateString(),chartVo,true,voList,industryId,x,y);
        chartVo.setX(x);
        chartVo.setY(y);
        voList.setChart(chartVo);
        if(x == null || x.size() ==0 || y == null || y.size() ==0){
            voList = null;
        }else{
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.TIR_INDUSTRY_INDEX_ALL_DATA+industryId,JSON.toJSONString(voList),300L);
        }
    }

    /**
     * 赚钱效应组装数据放入redis中
     * @param vo
     * @throws Exception
     */
    public void MarkMoneyEffectToCacheCalculation(GraliIntensity vo) throws Exception{
        String grailStr = null;
        //计算24小时前rowkey  getLastHourDateStr
        //String rowkey = DateUtils.getCurrentDateString();
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        ChartVo charDate = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        int ci =0;//记录最后数据,记录rowkey是否改变，如果等于一代表第一次改变，需要重新获取hbase数据
        ApiChartYObject charY = null;
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day < 2;day++){
            String rowkey = DateUtils.getNextDayDateYMD(-day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("赚钱效应数据化hbase数据查询","耗时"+rowkey,String.valueOf(System.currentTimeMillis()-hstart));
            LogTrace.info("赚钱效应数据化hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
        }
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
          /*  if(rowKeySame == 1 || rowKeySame == 0){//获取昨天的数据
                Long hstart = System.currentTimeMillis();
                grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_NAME
                        , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_FAMILY
                        , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_QUALIFIER
                        , nowRowKey);
                LogTrace.info("赚钱效应数据化hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
                LogTrace.info("赚钱效应数据化hbase数据查询","是否存在数据"+nowRowKey,StringUtils.isBlank(grailStr)?"无数据":"有数据"+grailStr);
            }
            if(StringUtils.isBlank(grailStr)) {
                if(hourStrInt==0){
                    hourStrInt =23;
                }else{
                    hourStrInt--;
                }
                continue;
            };*/
            Map<String,Object> moneyEffect = (Map<String, Object>) JSON.parse(grailStr);
            Object o = moneyEffect.get(nowHour);//获取当前时间数据
            if(o != null){
                List<MoneyEffect> listMoney = JSON.parseArray(JSON.toJSONString(o),MoneyEffect.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    MoneyEffect effect = listMoney.get(k);
                    if(effect.getCreateTime() == null || effect.getPerformance() == null) continue;
                    x.add(String.valueOf(effect.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setComment(StringUtils.isNotBlank(effect.getComment())?effect.getComment():"");
                    charY.setScore(effect.getScore().toString());
                    charY.setValue(effect.getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    y.add(charY);
                }
                if(ci==0 && listMoney != null && listMoney.size() >0){//最新数据评分放入到最外层
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore()!=null?listMoney.get(mongyLength-1).getScore().toString():"0");
                    vo.setResult(listMoney.get(mongyLength-1).getComment()!=null?listMoney.get(mongyLength-1).getComment():"");
                    vo.setCoinPerformance(listMoney.get(mongyLength-1).getPerformance()!=null?Double.valueOf(listMoney.get(mongyLength-1).getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString()):0);
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                    ci++;
                }
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        //获取大盘表现
           /* String grailIndex = rediscConfig.get(RedisKeysUtils.TIR_BROADER_INDEX, CoinRank.class);
            if(grailIndex!=null){
                BroaderIndex bi = JSON.parseObject(grailIndex,BroaderIndex.class);
                vo.setMarketPerformance(bi.getBroaderIndex()!=null?Double.valueOf(bi.getBroaderRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString()):null);
            }*/
        vo.setInterpretationId(2);
        vo.setInterpretation("赚钱效应");
        vo.setExplanation("昨日涨幅超过6%的货币今日表现是昨日投资的延续，当持续的收益表现良好时，一定程度上表明资金持续流入，市场走势趋强，反之则弱。");
        Collections.reverse(x);
        Collections.reverse(y);
        charDate.setX(x);
        charDate.setY(y);
        vo.setChart(charDate);
        if(x.size() == 0 || y.size() == 0){
            vo =  null;
        }else{
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.MARK_MONEY_EFFECT_FIVE_DATA,JSON.toJSONString(vo),300L);
        }
    }

    /**
     * 赚钱效应5分钟刷新缓存
     * @return
     */
    public ApiResultVo MarkMoneyEffectToCache() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            GraliIntensity listVo = new GraliIntensity();
            //获取所有行业,组装每个行业数据放到redis中
            this.MarkMoneyEffectToCacheCalculation(listVo);//去组装
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装赚钱效应放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }
    /**
     * 量能变化5分钟刷新缓存
     * @return
     */
    public ApiResultVo MarketInterpretationChangeToCache() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ApiMarketInterpretationChange listVo = new ApiMarketInterpretationChange();
            //获取所有行业,组装每个行业数据放到redis中
            this.MarketInterpretationChangeToCacheCalculation(listVo);//去组装
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装量能变化放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }
    /**
     * 量能变化5分钟组装数据到redis中
     * @param vo
     * @throws Exception
     */
    public void MarketInterpretationChangeToCacheCalculation(ApiMarketInterpretationChange vo) throws Exception{
        //计算24小时前rowkey  getLastHourDateStr
        //String rowkey = DateUtils.getCurrentDateString();
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        MoreChartVo charDate = new MoreChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        List<ApiChartYObject> y1 = new LinkedList<>();
        String grailStr = null;
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day > -2;day--){
            String rowkey = DateUtils.getNextDayDateYMD(day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("大盘量能变化hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
            LogTrace.info("大盘量能变化hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        }
        int ci =0;//记录最后数据
        ApiChartYObject charY = null;
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
            Map<String,Object> moneyEffect = (Map<String, Object>) JSON.parse(grailStr);
            Object o = moneyEffect.get(nowHour);//获取当前时间数据
            if(o != null){
                List<QuantumEnergy> listMoney = JSON.parseArray(JSON.toJSONString(o),QuantumEnergy.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    QuantumEnergy energy = listMoney.get(k);
                    if(energy == null || energy.getCreateTime() == null || energy.getAvgPrice() == null || energy.getAvgTurnover24h() == null){
                        continue; //判断内容不完整直接过滤
                    }
                    x.add(String.valueOf(energy.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setScore(energy.getScore().toString());
                    charY.setValue(energy.getAvgPrice()!=null?energy.getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    charY.setComment(StringUtils.isNotBlank(energy.getComment())?energy.getComment():"");
                    y.add(charY);
                    //y.add(energy.getAvgPrice()!=null?energy.getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    charY = new ApiChartYObject();
                    charY.setScore(energy.getScore().toString());
                    charY.setComment(StringUtils.isNotBlank(energy.getComment())?energy.getComment():"");
                    charY.setValue(energy.getAvgTurnover24h()!=null?energy.getAvgTurnover24h().divide(BigDecimal.valueOf(100000000)).setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    y1.add(charY);
                }
                if(ci==0){//最新数据评分放入到最外层
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore()!=null?listMoney.get(mongyLength-1).getScore().toString():"");
                    vo.setResult(listMoney.get(mongyLength-1).getComment()!=null?listMoney.get(mongyLength-1).getComment():"");
                    vo.setAveragePrice(listMoney.get(mongyLength-1).getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setAverageVolume(listMoney.get(mongyLength-1).getAvgTurnover24h().divide(BigDecimal.valueOf(100000000)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                }
                ci++;
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        //插入解释
        vo.setInterpretationId(2);
        vo.setInterpretation("量能变化");
        vo.setExplanation("用权重货币的价格以及每个货币被赋予的固定权重加权平均得到权重货币的价格指数，比较价格指数与权重货币交易额之间的关系，可以分析出近期大盘的走势。");
        Collections.reverse(x);
        Collections.reverse(y);
        Collections.reverse(y1);
        charDate.setX(x);
        charDate.setY(y);
        charDate.setY2(y1);
        vo.setChart(charDate);
        if(x.size() == 0 || y.size() == 0 || y1.size() == 0){
            vo =null;
        }else{
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.MARKET_INTERPRETATION_CHANGE,JSON.toJSONString(vo),300L);
        }
    }
    /**
     * 权重表现5分钟刷新缓存
     * @return
     */
    public ApiResultVo MarketWeightsPerformanceToCache() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ApiMarketWeightsPerformance listVo = new ApiMarketWeightsPerformance();
            //获取所有行业,组装每个行业数据放到redis中
            this.MarketWeightsPerformanceToCacheCalculation(listVo);//去组装
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("5分钟组装权重表现放入redis中，缓存5分钟，触发",e);
            e.printStackTrace();
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }
        return resultVo;
    }
    /**
     * 权重表现5分钟组装数据到redis中
     * @param vo
     * @throws Exception
     */
    public void MarketWeightsPerformanceToCacheCalculation(ApiMarketWeightsPerformance vo) throws Exception{
        String grailStr = null;
        //计算24小时前rowkey  getLastHourDateStr
       // String rowkey = DateUtils.getCurrentDateString();
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        ChartVo charDate = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day > -2;day--){
            String rowkey = DateUtils.getNextDayDateYMD(day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("权重表现hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
            LogTrace.info("权重表现hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        }
        int ci =0,rowKeySame=0;//记录最后数据,记录rowkey是否改变，如果等于一代表第一次改变，需要重新获取hbase数据
        ApiChartYObject charY = null;
        //取24小时内的数据
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
            Map<String,Object> weightsPerformanceMap = (Map<String, Object>) JSON.parse(grailStr);
            Object o = weightsPerformanceMap.get(nowHour);//获取当前时间数据
            if(o != null){
                List<WeightsPerformance> listMoney = JSON.parseArray(JSON.toJSONString(o),WeightsPerformance.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    WeightsPerformance wieghtPer = listMoney.get(k);
                    if(wieghtPer == null || wieghtPer.getCreateTime() == null || wieghtPer.getPerformance() == null){
                        continue; //判断内容不完整直接过滤
                    }
                    x.add(String.valueOf(wieghtPer.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setScore(wieghtPer.getScore().toString());
                    charY.setComment(StringUtils.isNotBlank(wieghtPer.getComment())?wieghtPer.getComment():"");
                    charY.setValue(wieghtPer.getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    y.add(charY);
                }
                if(ci == 0){//最新数据评分放入到最外层
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore().toString());
                    vo.setResult(listMoney.get(mongyLength-1).getComment());
                    vo.setWeightsPerformance(listMoney.get(mongyLength-1).getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                    ci++;
                }
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        //获取大盘表现
           /* String grailIndex = rediscConfig.get(RedisKeysUtils.TIR_BROADER_INDEX, CoinRank.class);
            if(grailIndex != null){
                BroaderIndex bi = JSON.parseObject(grailIndex,BroaderIndex.class);
                vo.setMarketPerformance(bi.getBroaderRiseFall().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
            }*/
        vo.setInterpretationId(3);
        vo.setInterpretation("权重表现");
        vo.setExplanation("权重货币是市值较大，具有代表性的20种货币，权重货币的价格涨幅越大，说明主力进场明显，反之则说明主力出逃明显。");
        Collections.reverse(x);
        Collections.reverse(y);
        charDate.setX(x);
        charDate.setY(y);
        vo.setChart(charDate);
        if(x.size() == 0 || y.size() == 0 ){
            vo =null;
        }else{
            //数据插入到redis中
            rediscConfig.set(RedisKeysUtils.MARKET_WEIGHTS_PERFORMANCE,JSON.toJSONString(vo),300L);
        }
    }

    /**
     * 返回权重指数日K线信息以及最新权重指数信息
     * @param type
     * @return
     */
    public ApiResultVo<ApiWeightIndexKlineVo> getWeightIndexKline(String page, String pagesize){
    	LogTrace.info("权重指数", "权重指数日K线信息请求参数", "页数：" + page + "，每页条数：" + pagesize);
    	ApiWeightIndexKlineVo awik = new ApiWeightIndexKlineVo();
    	//获取最新的权重指数信息
    	String last = rediscConfig.get(RedisKeysUtils.TIR_LAST_WEIGHT_INDEX);
    	WeightIndexLastInfo wili = new WeightIndexLastInfo();
    	if(last == null || "".equals(last.trim())){
    		//缓存为空，递归获取最新的权重指数信息
    		getApiWeightIndexKlineVo(wili, 0);
    	}else{
    		//缓存中获取最新的权重指数信息
    		Map<String, String> map = JSON.parseObject(last, Map.class);
    		wili.setHighIndex(map.get("highindex"));
    		wili.setLowIndex(map.get("lowindex"));
    		wili.setWeightIndex(map.get("index"));
    		wili.setRiseFall(map.get("rise"));
    	}
    	//根据时间维度转换天数，获取所需要的日K线数量
		KlineWeightIndex kwi = new KlineWeightIndex();
		kwi.setkName("权重日K线");
		kwi.setPage(Integer.valueOf(page) * Integer.valueOf(pagesize));
		kwi.setPagesize(Integer.valueOf(pagesize));
		List<KLine> list = kLineMapper.selectListByTimeType(kwi);
		List<KLine> l = new ArrayList<>();
		for(KLine k : list){
			try {
				k.setKDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(k.getKDate() + " 00:00:00").getTime() + "");
				l.add(k);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		Collections.reverse(l);
    	awik.setWikList(l);
    	//存入返回结果
    	awik.setWili(wili);
    	ApiResultVo<ApiWeightIndexKlineVo> apiResultVo = new ApiResultVo<>();
    	apiResultVo.setData(awik);
    	apiResultVo.setPages(Integer.valueOf(page));
    	apiResultVo.setTotal(l.size());
    	apiResultVo.setDataStamp(System.currentTimeMillis());
    	apiResultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
    	apiResultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
    	LogTrace.info("权重指数", "权重指数日K线信息返回参数", JSON.toJSONString(apiResultVo));
    	return apiResultVo;
    }

    /**
     * 递归获取最新的权重指数信息
     * @param wili
     * @param day
     */
    public void getApiWeightIndexKlineVo(WeightIndexLastInfo wili, int day){
    	try {
			String data = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_NAME
			        , HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_FAMILY
			        , HbaseTableUtils.CALCULATE_TICKER_QUALIFIER
			        , HbaseTableUtils.HOME_INDEX_EVERY_DAY_WEIGHTINDEX_ROWKEY+DateUtils.getCurrentDateString());

			if(data != null && !"".equals(data.trim())){
				JSONArray ja = JSONArray.parseArray(data);
				//获取收盘权重指数
				JSONObject objwe = (JSONObject)ja.get(ja.size() - 1);
				WeightIndex we = objwe.toJavaObject(WeightIndex.class);
				//初始化高开权重指数和低收权重指数
				BigDecimal highopen = we.getWeightIndex();
				BigDecimal lowclose = we.getWeightIndex();
				for(int i = 0; i < ja.size(); i++){
					JSONObject obj = (JSONObject)ja.get(i);
					WeightIndex w = obj.toJavaObject(WeightIndex.class);
					BigDecimal big = w.getWeightIndex();
					if(big.compareTo(lowclose) == -1){
						//获取最小权重指数
						lowclose = big;
					}else if(big.compareTo(highopen) == 1){
						//获取最大权重指数
						highopen = big;
					}
				}
				wili.setHighIndex(highopen + "");
		    	wili.setLowIndex(lowclose + "");
		    	wili.setWeightIndex(we.getWeightIndex() + "");
		    	wili.setRiseFall(we.getWeightRiseFall() + "");
			}else{
				if(day > -30){
					getApiWeightIndexKlineVo(wili, --day);
				}
			}
		} catch (HbaseConnectionExcetion | HbaseGetTableExcetion | IOException | HbaseCloseExcetion e) {
			e.printStackTrace();
		}
    }


    /**
     * 获取大盘K线日K数据
     * @return
     */
    public ApiResultVo<List<ApiKlineBroader>> getBroaderKline(Integer page ,Integer size) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
//        BeanUtils.copyProperties();
        Map<String , Integer> map = new HashMap<>();
        if(size != null & size >100){
            size = 100;
        }
        map.put("page" , page * size);
        map.put("size" , size);
        try {
            List<ApiKlineBroader> list = new ArrayList<>();
            List<KLineBroaderIndex> kLineBroaderIndexList = kLineBroaderIndexMapper.selectByPage(map);

            for (KLineBroaderIndex k : kLineBroaderIndexList) {

                ApiKlineBroader apiKlineBroader = new ApiKlineBroader();
                BeanUtils.copyProperties(k , apiKlineBroader);

                list.add(apiKlineBroader);
            }
            if(kLineBroaderIndexList != null && kLineBroaderIndexList.size() >0 ){
                resultVo.setData(list);
                resultVo.setTotal(list.size());
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            }else{
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
            }
            LogTrace.info("getBroaderKline","data" ,kLineBroaderIndexList+"");

        }catch (Exception e){
            LogTrace.error(e.getMessage() , e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }

        return resultVo;
    }

    /**
     * 获取大盘指数涨跌幅
     * @return
     */
    public ApiResultVo getBroaderIndexHeader() {
        Long start = System.currentTimeMillis();
        LogTrace.info("大盘指头部信息", "start", start+"");

        ApiResultVo<ApiBroaderIndexHeaderVo> resultVo = new ApiResultVo<>();

        resultVo.setTradeId(LogTrace.getTrace().getTraceId());

        try {
            ApiBroaderIndexHeaderVo apiBroaderIndexHeaderVo = new ApiBroaderIndexHeaderVo();

            String tirBroaderIndex = rediscConfig.get(RedisKeysUtils.TIR_BROADER_INDEX);
            BroaderIndex broaderIndex = JSONObject.parseObject(tirBroaderIndex , BroaderIndex.class);

            apiBroaderIndexHeaderVo.setBroaderIndex(broaderIndex.getBroaderIndex().toString());
            apiBroaderIndexHeaderVo.setBroaderRiseFall(broaderIndex.getBroaderRiseFall().toString());
            //设置最高大盘指数
            String highKey = RedisKeysUtils.TIR_BROADER_INDEX_HIGH+DateUtils.getCurrentDateString();
            LogTrace.info("getBroaderIndexHeader","highKey",highKey);
            //设置最低大盘指数
            String lowKey = RedisKeysUtils.TIR_BROADER_INDEX_LOW+DateUtils.getCurrentDateString();
            LogTrace.info("getBroaderIndexHeader","lowKey",lowKey);

            apiBroaderIndexHeaderVo.setHighValue(rediscConfig.get(highKey));
            apiBroaderIndexHeaderVo.setLowValue(rediscConfig.get(lowKey));

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());

            resultVo.setData(apiBroaderIndexHeaderVo);
        }catch (Exception e){
            LogTrace.error(e.getMessage(),e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
        }

        return resultVo;
    }
}
